/**
* @Title: caseHandle_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
* Company:中国平安
* ex-xieqi001
* @Project HIMS-FWA
* @date 2014年11月11日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('WarnAuditPostCtrl', ['$scope','FwaTabsetService','BaseURL','Modal','WarnAuditPostService',
	                                function($scope,FwaTabsetService,baseUrl,Modal,WarnAuditPostService){
		
		$scope.barLeftOption ={
				title:{
					text: '预警事件—时间趋势图',
			        x: 'left'
				},
				grid:{
					x:30,
					y:40,
					x2:10,
					y2:40,
					borderColor:'#fff'
				},
				xAxis : [{
		             type : 'category',
		             boundaryGap: true,
		             data : ['']
		         }],
		         series:[],
		         color:['#56C8E3']
		};
       
		$scope.barOption = {
				grid:{
					x:30,
					y:40,
					x2:10,
					y2:40,
					borderColor:'#fff'
				},
				title : {
			        text: '不合理费用—时间趋势图',
			        x: 'left'
			    },
				xAxis : [{
		             type : 'category',
		             boundaryGap: true,
		             data : ['']
		         }],
		         series:[],
		         color:['#56C8E3']
		};
		//获取echarts 数据
		WarnAuditPostService.getUnreasonable().success(function(res){
			$scope.barOption.xAxis = [{
	             type : 'category',
	             boundaryGap: true,
	             data : res.dateViewList
	         }];
			
			var barSeries  = [];
			barSeries.push({
				name:'事件数',
				type:'bar',
				barWidth:15,
				data:res.errorCostList
			});
			$scope.barOption.series = barSeries; 
			
			$scope.barLeftOption.xAxis = [{
	             type : 'category',
	             boundaryGap: true,
	             data : res.dateViewList
	         }];
			
			var barLeftSeries  = [];
			barLeftSeries.push({
				name:'事件数',
				type:'bar',
				barWidth:15,
				data:res.warnNumList
			});
			$scope.barLeftOption.series = barLeftSeries; 
		});
		var cellTemplate = 
			'<td>'+
				'<a  ng-click="clickLink(data)">确定</a>'+
			'</td>';
		       $scope.columns = [
					        {label:'预警编号',map:'warnNoBiz',width:'11%'},
					        {label:'预警事件名称',map:'summary',width:'15%'},
					        {label:'机构名称',map:'medicalOrgName',width:'18%'},
					        {label:'处理方式',map:'process',width:'11%'},
					        {label:'预警时段',map:'happenDate',width:'14%'},       
					        {label:'受理时间',map:'warnDate',width:'11%'},
					        {label:'事件状态',map:'actName',width:'11%'},
					        {label:'操作',width:'9%',cellClass:'text-left', cellTemplate:cellTemplate}
					    ];
		       $scope.tableData = [];
		       $scope.totalCount = 0;
//		WarnAuditPostService.warningAuditQuery().success(function(res){
//			
//            angular.forEach(res.result,function(data,index){
//            	
//            	$scope.tableData.push(data);
//            });
//           
//            $scope.totalCount =  $scope.totalCount + res.result.length;
//        });
		
		
		var isFlag = true;
		//跳转路由监听
		$scope.$on('$stateChangeSuccess', function(event , toState, toParams, fromState){
			if(toState.name && toState.name.indexOf('workingArea.warnAuditPost') != -1) {
				if (isFlag) {
					query();
					isFlag = false;
				}
				else {
					isFlag = true;
				}
			}
		});
		
		function query() {
			WarnAuditPostService.warningResultAuditQuery().success(function(res){
	            $scope.tableData = res.result;
	            $scope.totalCount = res.result.length;
	        });
		}
		
		if (isFlag) {
			query();
			isFlag = false;
		}
		else {
			isFlag = true;
		}
		
		$scope.clickLink = function (data){
			var urlFlag="2";
			if(data.actNo==='N2014007'){
				FwaTabsetService.selectTab('warnQueryResultAudit.warningResultAudit',{warnNo:data.warnNo,actNo:data.actNo,urlFlag:urlFlag},false);
        	}else{
        		FwaTabsetService.selectTab('warnQueryAudit.warningAuditWarn',{warnNo:data.warnNo,actNo:data.actNo,urlFlag:urlFlag},false);
        	}
			
	   }
	}]);
})();
